import type { RowData } from "naive-ui/es/data-table/src/interface";

export { RowData };

type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };

/** 完全互斥，比竖线更严格 */
export type XOR<T extends RowData, U extends RowData> =
  | (Without<T, U> & U)
  | (Without<U, T> & T);

/** 多个类型之间的完全互斥 */
export type XORMultiple<Types extends RowData[]> = Types["length"] extends 0
  ? never
  : Types["length"] extends 1
  ? Types[0]
  : Types["length"] extends 2
  ? XOR<Types[0], Types[1]>
  : Types extends [infer First, ...infer Rest]
  ? First extends RowData
    ? Rest extends RowData[]
      ? XOR<First, XORMultiple<Rest>>
      : never
    : never
  : never;

/** 字典数据类型 */
export type Dic<T> = XOR<{ dicData: T[] }, { dicUrl: string }>;

type Capitalize<T extends string> = T extends `${infer F}${infer Rest}`
  ? `${Uppercase<F>}${Rest}`
  : T;

/** 类型字段加上前缀 */
export type PrefixRecord<S extends string, T extends RowData> = {
  [K in keyof T as `${S}${Capitalize<string & K>}`]: T[K];
};

/** keyof 只能是字符串类型 */
export type StringKeys<T> = {
  [K in keyof T]: string extends K ? string : number extends K ? string : K;
} extends { [_ in keyof T]: infer U }
  ? U
  : string;

export type WithoutUndefined<T> = T extends undefined ? never : T;
